Sometimes we want different versions of tensorflow so we can run someone elses code. Sometimes we want different versions of python i.e. 2.7 or 3.6. Sometimes we want both. We can control all of that with conda environments and convenient bash aliases

Create Descriptive Anaconda Environment

We must first create an environment for the specific version of python we are interested in

>>> conda create --name python3.6-tensorflow1.1 python=3.6

Notice the python=3.6 at the end? This is how we tell anaconda to install a local python kernel with the specified version.

Add Alias for Easy Activation

Next we want to active the environment. However, we don't want to type in that cumbersome name everytime, but we do want the verbosity to be displayed while developing to remove any ambiguities. Bash aliases to the rescue. Add the following line in your .bashrc file.

alias py36tf11='source activate python3.6-tensorflow1.1'

Don't forget to source your updated bashrc into the current shell session...

>>> source ~/.bashrc

With that, our new alias should be active and we can easily enter our custom python environment with the line

>>> py36tf11

You should see the following output.

>>> (python3.6-tensorflow1.1) username@hostname:

Install Tensorflow

Next we will fill this environment with the packages we will be using. This is more personal and you can add whatever you want. The packages we all will most likely add by default are as follows

conda install ipython numpy scipy matplotlib tqdm

Then install the tensorflow version you want. To do this let us first take a look at the available packages...

>>> conda search tensorflow

>>> Fetching package metadata .........
tensorflow 0.10.0rc0 np111py27_0 defaults 0.10.0rc0 np111py34_0 defaults 0.10.0rc0 np111py35_0 defaults 1.0.1 np112py27_0 defaults 1.0.1 np112py35_0 defaults 1.0.1 np112py36_0 defaults 1.1.0 np111py27_0 defaults 1.1.0 np111py35_0 defaults 1.1.0 np111py36_0 defaults 1.1.0 np112py27_0 defaults 1.1.0 np112py35_0 defaults 1.1.0 np112py36_0 defaults tensorflow-gpu 1.0.1 py27_4 defaults 1.0.1 py35_4 defaults 1.0.1 py36_4 defaults 1.1.0 np111py27_0 defaults 1.1.0 np111py35_0 defaults 1.1.0 np111py36_0 defaults 1.1.0 np112py27_0 defaults 1.1.0 np112py35_0 defaults 1.1.0 np112py36_0 defaults

We see the package names, their version numbers, and which version of python and numpy that they are compatible with. For example, tensorflow1.0.1 is not compatible with numpy1.1.1. So decide whether you want gpu functionality and which version you want and install it as follows

>>> conda install tensorflow=1.1.0

This process can be repreated with different versions of python and tensorflow.

Removing Anaconda Environments

conda remove --name python3.6-tensorflow1.1 --all

The --all flag must be included to remove environments. Otherwise it will think the name specified is a package.


In [ ]: